<template>
  <el-dialog
    title="创建会费缴纳"
    class="gl_dialog_TitleLine gl_dl_footer"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    width="530px"
  >
    <el-form ref="courseForm" class="gl_form_mini" :model="CreateFeeRequestInput" style="padding: 0 30px" :rules="formdata_Rules" label-width="120px">
      <div>
        <div>
          <el-form-item label="创建会费缴纳" prop="name">
            <el-input
              v-model="CreateFeeRequestInput.name"
              style="width:320PX"
              type="input"
              size="mini"
              placeholder="请输入内容"
              maxlength="10"
              show-word-limit
            />
          </el-form-item>
        </div>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" :loading="submitLoading" size="mini" @click="submit('courseForm')">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { api_POST_ClubFeeRequest, api_PUT_ClubFeeRequestId } from '@/extend/api/hallswaggerApi/app.js';
import { CreateFeeRequestInput } from '@/lib/form/hall/swaggerForm';
import validator from '@/lib/validate/index.js';
export default {
  data() {
    return {
      id: '',
      CreateFeeRequestInput: new CreateFeeRequestInput(),
      submitLoading: false,
      typeRadios: 3,
      examRadios: 6,
      title: '',
      textarea: '',
      dialogVisible: false,
      formdata_Rules: { // 必填项，验证密码格式
        name: [
          validator.required('会费缴纳名称不能为空')
        ]
      }
    };
  },
  watch: {
    dialogVisible: {
      handler() {
        if (this.dialogVisible === false) {
          this.$refs.courseForm.resetFields();
          this.CreateFeeRequestInput = new CreateFeeRequestInput();
          this.id = '';
        }
      },
      deep: true
    }
  },
  methods: {
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          if (this.id) {
            api_PUT_ClubFeeRequestId(this.id, this.CreateFeeRequestInput).then(res => {
              this.$message({ type: 'success', message: '更新成功' });
              this.submitLoading = false;
              this.dialogVisible = false;
              this.$parent.gettablelist();
            }, error => {
              this.submitLoading = false;
              const _msg = error.error.message || error.message;
              this.$message({ type: 'error', message: _msg });
            });
          } else {
            api_POST_ClubFeeRequest(this.CreateFeeRequestInput).then(res => {
              this.$message({ type: 'success', message: '创建成功' });
              this.submitLoading = false;
              this.dialogVisible = false;
              this.$parent.gettablelist();
            }, error => {
              this.submitLoading = false;
              const _msg = error.error.message || error.message;
              this.$message({ type: 'error', message: _msg });
            });
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
.up_button {
  display: flex;
height: 40px;
align-items: center;
}
.up_button>div {
  margin-right: 16px;
}
</style>
